/*******************************************************************************
 * Copyright 2011 Mauro Luigi Drago (drago.luigi@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.bytenose.extrautils.functional;

import com.bytenose.extrautils.patterns.builder.Builder;

/**
 * A mutable non-materialized tuple.
 * This is the mutable companion of {@link Tuple2}.
 * It can also be used as a builder of {@link Tuple2}.
 * @author Mauro Luigi Drago
 *
 * @param <A1> the type of the first value.
 * @param <A2> the type of the second value.
 */
public final class MutableTuple2<A1, A2> 
	implements ITuple2<A1, A2>, Builder<Tuple2<A1, A2>> {
	
	private A1 value1;
	private A2 value2;
	
	/**
	 * Creates a new {@link MutableTuple2}
	 * @param value1 the first value.
	 * @param value2 the second value.
	 */
	public MutableTuple2(A1 value1, A2 value2) {
		this.value1 = value1;
		this.value2 = value2;
	}
	
	@Override
	public A1 getValue1() {
		return value1;
	}
	
	@Override
	public A2 getValue2() {
		return value2;
	}
	
	/**
	 * Sets the first value.
	 * @param value1 the value.
	 */
	public void setValue1(A1 value1) {
		this.value1 = value1;
	}

	/**
	 * Sets the second value.
	 * @param value2 the value.
	 */
	public void setValue2(A2 value2) {
		this.value2 = value2;
	}

	/**
	 * Creates a new {@link MutableTuple2}
	 * @param <T1> the type of the first value.
	 * @param <T2> the type of the second value.
	 * @param value1 the first value.
	 * @param value2 the second value.
	 */
	public static <T1,T2> MutableTuple2<T1,T2> create(T1 value1, T2 value2) {
		return new MutableTuple2<T1, T2>(value1, value2);
	}
	
	@Override
	public Tuple2<A1,A2> materialize() {
		return Tuple2.create(value1, value2);
	}

	@Override
	public Tuple2<A1, A2> build() {
		return materialize();
	}
}
